<?php

namespace App\Models\Finance;

use App\Models\Company;
use Illuminate\Database\Eloquent\Model;

/**
 * 参与薪资计算的原始数据定义
 *
 * Date: 2018/5/28
 * @author George
 * @package App\Models\Finance
 */
class Original extends Model
{
	/**
	 * 定义可批量填充字段
	 *
	 * @var array
	 * Date: 19/03/2018
	 * @author George
	 */
	protected $guarded = ['id'];

	/**
	 * 定义默认值
	 *
	 * Date: 2018/6/5
	 * @author George
	 * @return Original[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection
	 */
	public static function default()
	{
		$originals = self::all()->map(function ($original) {
			$original->status = false;
			return $original;
		});
		return $originals;
	}

	/**
	 * 获取企业信息
	 *
	 * Date: 2018/6/5
	 * @author George
	 * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
	 */
	public function companies()
	{
		return $this->belongsToMany(Company::class, 'company_original_pivot', 'original_id', 'company_id', 'id', 'id')
			->withPivot(['pattern_id', 'status']);
	}
}
